/*
* Unit Test Bootstrap
* Autor: Tomasz Jaworski, 2018-2019
*
* Test dla zadania Histogram
* Autor testowanej odpowiedzi: Szymon Ptak
* Test wygenerowano automatycznie o 2019-08-22 17:26:49.779346
*
* Debug:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <setjmp.h>
#include <assert.h>
#define _RLDEBUG_API_
#include "unit_helper_v2.h"
#include "rdebug.h"
#include "tested_declarations.h"
#include "rdebug.h"
//
// Elementy globalne dla całego testu
//
//
// Test 1: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST1(void)
{
// informacje o teście
test_start(1, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 2, 0, 0, 0, 0, 2, 0, 2, 3, 0};
int output[] = {-1, -1, 1, 1, 0, 2, -2, 2, 0, -1, 2};
printf("#####START#####");
int res = create_histogram((float[]){8.382878, 1.724498, 6.022452, 1.590785, 8.332282, 9.666826, 6.917846, 9.908814, 9.739670}, 9, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 2, 0, 0, 0, 0, 2, 0, 2, 3, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 2: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST2(void)
{
// informacje o teście
test_start(2, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {8, 5, 2, 9, 4, 4, 7, 10, 2, 6, 3};
int output[] = {-2, -1, -2, -2, -2, -1, 1, 1, 2, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){9.948818, 9.420303, 3.130455, 3.377955, 5.651045, 10.705945, 7.404605, 1.566142, 3.578842, 6.290629, 0.161380, 1.082121, 9.338372, 5.051323, 6.371987, 4.255961, 3.684151, 6.815648, 7.364137, 0.167983, 10.893606, 7.643505, 3.545348, 5.705787, 4.346499, 0.362880, 3.287038, 1.071696, 7.189949, 10.376143, 9.448308, 3.889956, 3.390570, 7.480911, 8.635205, 1.394802, 8.380568, 3.729525, 9.442761, 7.292089, 6.924091, 0.053951, 0.928347, 7.935640, 2.943338, 1.315393, 7.571188, 6.586347, 7.405377, 0.050748, 4.735436, 4.449128, 0.906332, 2.561138, 6.270292, 5.796877, 9.010095, 0.829519, 7.235370, 6.997968}, 60, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [8, 5, 2, 9, 4, 4, 7, 10, 2, 6, 3]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 3: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST3(void)
{
// informacje o teście
test_start(3, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {24, 15, 12, 18, 15, 21, 19, 10, 18, 19, 17};
int output[] = {-1, -1, 2, -1, 0, 1, -1, 2, -1, 1, -2};
printf("#####START#####");
int res = create_histogram((float[]){5.181272, 5.335282, 8.934185, 2.549452, 2.091114, 0.844771, 10.981632, 5.234913, 3.547555, 2.337207, 10.283226, 3.539312, 8.820429, 5.487869, 9.381474, 9.425542, 0.299055, 2.446234, 6.627228, 5.404255, 1.361776, 3.204493, 5.541912, 0.976746, 2.793397, 7.286592, 5.688458, 9.780434, 0.099537, 1.204239, 4.345602, 2.474932, 0.057918, 8.872088, 6.605097, 4.224618, 0.850466, 8.836114, 6.640438, 6.855612, 10.312279, 1.513823, 5.163469, 4.818210, 1.782714, 1.876656, 10.850348, 6.921867, 7.225480, 6.156136, 3.005343, 0.767920, 1.501924, 1.320120, 9.109350, 6.674871, 0.951539, 10.151325, 0.073839, 4.837874, 4.402590, 0.576473, 7.342132, 3.611137, 2.874718, 9.312528, 1.234119, 5.026876, 3.008490, 9.323365, 0.573211, 10.383973, 5.431459, 10.709618, 8.884794, 1.195700, 3.226262, 0.320742, 5.227432, 1.341599, 9.482696, 3.386814, 1.541618, 7.683354, 8.541503, 10.816333, 8.686637, 5.975026, 9.655771, 6.633886, 10.318482, 6.089740, 8.043410, 9.289198, 8.423084, 7.140480, 5.456886, 4.892213, 4.665898, 4.435438, 2.111504, 3.323418, 9.170326, 0.907339, 3.473838, 8.856306, 9.093883, 1.035450, 6.367998, 5.274262, 1.097468, 6.349675, 8.710131, 6.702388, 9.312568, 10.652857, 4.783404, 6.412654, 7.911004, 7.465189, 3.166572, 6.684450, 0.639281, 6.339375, 5.647329, 0.012710, 4.301455, 2.179727, 2.694844, 6.762101, 4.358799, 10.627749, 9.083117, 5.571825, 3.447723, 8.447186, 9.921684, 10.389882, 5.523412, 10.848570, 8.230109, 4.373206, 5.327215, 7.233870, 4.485880, 0.943355, 10.033166, 6.282503, 3.159109, 3.939060, 5.202152, 9.816050, 7.858737, 3.679333, 9.391236, 7.276910, 5.081713, 6.585119, 10.650353, 8.972369, 0.739048, 9.621616, 9.920565, 3.567783, 3.327925, 4.046107, 0.486074, 8.038970, 0.550904, 0.489167, 0.639665, 5.864290, 2.788420, 3.285691, 0.906326, 2.856828, 1.064218, 8.480207, 4.205017, 1.360894, 8.505276, 9.150158, 0.819439, 10.128186, 10.384979, 0.840716, 8.829913, 6.168690}, 188, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [24, 15, 12, 18, 15, 21, 19, 10, 18, 19, 17]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 4: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST4(void)
{
// informacje o teście
test_start(4, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0};
int output[] = {2, -1, 0, -1, 0, -1, 1, -2, 1, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){-5.914175, 1.000903, -1.472699, 7.750066, -4.889822, 8.613822, 5.101742}, 7, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 5: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST5(void)
{
// informacje o teście
test_start(5, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {7, 2, 6, 6, 3, 1, 6, 5, 7, 5, 0};
int output[] = {-1, 0, -1, -1, -2, 2, -2, -1, 0, 1, -2};
printf("#####START#####");
int res = create_histogram((float[]){9.384868, -2.137276, -0.716167, -3.514408, 2.757848, 0.789572, 6.208380, -4.198907, -5.529085, 3.209477, 7.032569, -0.609188, 8.184244, -3.283137, -9.351251, -3.528994, 8.839159, -3.553794, -9.729634, 7.400520, 2.821128, -8.692939, 2.121578, 8.930488, 6.113706, 9.109793, -4.632537, -3.343794, 1.344414, -7.275113, 8.455961, -3.877069, -3.699490, 0.489437, 3.456988, 3.471823, 0.301896, -9.096087, 3.648309, 3.618817, 9.902088, -7.096895, -7.552100, -4.422787, 0.313916, -7.068855, -3.558158, -3.478246, -6.605577, 0.131770, -4.223291, -6.605151, -2.920998, -3.994765, -2.740974, -7.597777, 3.598043, 6.095181, -2.258658, 1.933556, -5.296172, -3.986074, -2.133384, -2.446591, -2.261106, 8.413103, 6.571053, 7.517862, 2.341519, -9.604943, 7.604711, 5.507982, 7.783547, 0.348672, 0.682431, 2.999848, -7.688984, -6.640338, -4.038075, -0.391602, 6.872483, -4.990169, -4.534210, -6.617819, 4.662678, -6.603904, 8.600798, 6.194170, 4.458156, -0.105916, -0.123830, 9.759498, -6.176007, -6.354507, 4.524518, 9.074131, 8.667663, 2.095432}, 98, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [7, 2, 6, 6, 3, 1, 6, 5, 7, 5, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 6: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST6(void)
{
// informacje o teście
test_start(6, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {3, 2, 8, 5, 6, 2, 0, 2, 2, 6, 6, 10, 3, 7, 5, 2, 4, 6, 5, 1, 0};
int output[] = {-2, 0, 0, -1, 1, 1, 0, 0, 2, -1, 2, 2, 2, -1, -1, 1, 2, -2, -1, -2, 1};
printf("#####START#####");
int res = create_histogram((float[]){15.604841, 17.701599, 17.219995, 8.899321, 2.657922, 17.140818, 2.463662, 13.817275, 16.865262, 18.123644, 8.270736, 2.102800, 4.957706, 12.845208, 11.975805, 16.735362, 4.576413, 7.618630, 11.905305, 14.872465, 5.078886, 13.365574, 9.120502, 18.643772, 5.139930, 3.456487, 18.722243, 3.742442, 11.253308, 16.001097, 11.261353, 10.928677, 3.975880, 9.704365, 16.802101, 2.782471, 7.380183, 12.213379, 10.130841, 10.713075, 1.831727, 14.914049, 11.622952, 13.015832, 10.590758, 2.922956, 2.633218, 15.509572, 3.100913, 4.649161, 1.725095, 11.081441, 13.552767, 13.098647, 19.032330, 17.352968, 10.733079, 11.568106, 11.728820, 17.374869, 9.816925, 9.278997, 0.755071, 4.919474, 12.396650, 14.143930, 0.706015, 11.343903, 3.769724, 13.521944, 9.381061, 2.455995, 18.637256, 14.284055, 17.738085, 0.206222, 4.018851, 18.014174, 9.531517, 10.566895, 4.576968, 2.600731, 13.910947, 14.345575, 11.931694}, 85, output, 21);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 21; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [3, 2, 8, 5, 6, 2, 0, 2, 2, 6, 6, 10, 3, 7, 5, 2, 4, 6, 5, 1, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 21; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 7: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST7(void)
{
// informacje o teście
test_start(7, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {12, 18, 13, 18, 7, 17, 11, 6, 13, 17, 12, 12, 13, 12, 17, 11, 16, 13, 9, 5, 12, 13, 20, 7, 9, 8, 12, 13, 8, 12, 9, 10, 18, 13, 13, 18, 17, 14, 14, 13, 11, 12, 26, 16, 13, 20, 17, 15, 19, 10, 7, 14, 21, 10, 14, 13, 22, 15, 10, 4, 15, 13, 0};
int output[] = {-2, 2, -1, 1, 0, -1, 1, -2, 1, 1, 2, 2, 2, -1, 1, 2, 1, -1, -2, -1, -1, 2, -1, -2, -1, 2, -1, -1, -2, -2, 1, 2, 2, -2, 2, -2, 2, -1, -2, 2, -2, -2, 0, -2, -2, 0, -2, 2, -1, -1, -2, 0, 2, 2, 1, 0, 1, 2, 0, 2, -2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){57.421325, 9.792326, 25.706746, 2.630051, 56.194885, 9.509868, 52.186973, 45.791618, 59.421067, 11.126329, 21.916607, 55.095171, 25.982176, 16.732733, 1.322049, 1.024627, 49.090680, 3.289015, 0.684649, 47.079001, 60.213215, 12.141960, 36.892102, 1.936302, 46.549807, 28.281001, 22.642679, 52.320416, 56.659323, 0.910303, 37.754158, 2.363997, 1.181663, 48.394965, 16.458903, 48.228522, 47.191475, 23.559527, 55.168018, 25.070178, 2.062814, 56.334216, 48.475709, 2.766001, 56.947064, 0.819159, 36.963215, 27.683128, 22.404240, 52.648315, 56.243240, 3.929951, 32.591320, 29.182750, 31.724667, 48.326331, 28.077152, 8.272810, 45.568162, 40.187919, 11.866827, 49.796298, 8.794717, 46.747612, 34.710789, 43.915373, 4.936754, 21.532295, 10.097898, 27.844305, 6.226546, 17.515430, 60.718066, 11.384805, 14.318560, 21.387646, 56.861801, 33.445659, 20.076952, 48.331662, 48.261769, 50.567940, 52.130829, 11.204247, 51.210046, 32.168740, 20.394995, 16.556365, 2.067620, 12.362161, 52.499050, 4.452065, 44.316231, 10.226184, 16.040928, 6.845290, 18.360792, 14.191275, 18.126049, 14.487377, 42.746012, 51.112821, 52.247121, 43.109038, 11.182941, 37.847667, 12.014613, 19.274558, 3.055463, 35.701616, 42.657128, 31.225737, 45.687475, 25.972913, 56.898125, 39.604122, 40.987504, 53.085238, 11.127119, 58.196144, 47.713894, 61.323101, 43.400047, 1.922063, 5.269367, 43.701872, 33.713837, 17.497188, 47.557415, 52.002832, 2.791746, 53.276476, 36.429513, 40.324790, 14.233413, 53.761124, 61.177674, 27.604714, 22.333717, 44.682045, 5.924760, 21.148178, 3.840334, 14.985222, 35.763198, 32.498530, 42.490393, 1.676313, 36.180902, 46.962825, 32.732889, 9.549451, 36.558732, 50.094228, 7.321554, 47.082969, 51.418138, 38.911907, 14.636209, 14.858821, 14.760976, 11.493309, 57.562824, 37.210042, 43.199719, 42.841060, 38.204555, 61.540284, 40.542637, 39.285049, 26.616882, 17.168681, 39.539011, 1.705775, 13.738837, 44.499956, 46.170851, 49.294443, 37.558471, 54.402982, 16.193740, 42.377174, 41.397559, 54.607231, 39.411098, 9.423302, 11.364008, 35.839558, 16.924124, 53.573577, 37.451611, 12.872612, 16.808712, 17.297244, 17.711170, 50.181597, 8.992435, 5.537246, 30.493974, 39.447179, 0.717979, 33.501583, 60.576277, 60.540660, 51.261462, 42.671598, 0.306599, 29.651636, 52.434761, 55.886022, 7.534056, 3.123425, 18.449282, 48.282268, 35.571936, 15.827724, 6.856057, 20.850023, 49.339428, 21.997445, 38.999017, 24.698784, 53.113234, 3.916548, 40.295885, 39.584876, 3.553597, 2.279851, 45.936425, 41.398287, 30.538087, 57.957272, 17.453776, 61.396818, 52.298307, 57.578134, 33.055819, 60.551148, 47.478581, 41.265039, 47.749778, 59.099886, 60.455900, 58.970549, 29.557955, 52.159750, 4.265119, 61.309762, 52.767068, 4.038693, 23.923336, 43.688147, 15.573308, 45.205789, 32.609474, 10.523617, 45.518672, 36.465336, 56.356002, 25.502344, 22.162347, 9.110584, 35.668909, 41.202597, 49.165116, 36.831980, 61.191812, 46.725957, 27.411805, 56.054473, 38.037295, 42.113252, 35.733899, 21.385896, 35.561226, 38.900552, 2.981113, 26.841494, 51.728547, 12.738354, 0.505738, 45.558697, 48.502809, 54.986147, 21.333950, 35.413810, 9.358262, 8.434934, 0.712622, 26.273495, 42.584255, 60.828316, 22.263462, 33.491804, 38.566550, 18.872547, 46.117445, 50.695442, 27.752048, 56.610969, 29.387977, 35.204362, 61.276512, 39.231305, 22.304049, 34.156647, 45.128320, 45.503293, 46.254208, 10.107139, 48.607404, 55.556759, 44.002965, 48.153376, 42.487221, 9.612511, 13.265398, 6.438499, 55.537475, 12.383068, 6.127827, 3.406887, 58.444454, 5.904768, 56.517084, 22.564019, 48.500921, 6.807744, 22.936974, 17.630306, 17.403668, 57.499838, 45.931336, 36.215217, 21.363168, 43.536905, 45.846098, 15.697886, 31.991578, 3.919897, 3.442561, 51.864868, 8.005381, 40.654036, 56.967678, 32.593837, 55.870105, 61.226678, 49.306565, 48.763220, 39.029428, 55.684841, 46.736805, 10.254491, 2.392313, 32.023206, 51.215216, 42.350015, 47.437571, 32.363998, 45.507250, 5.893843, 58.881068, 13.421731, 35.925776, 15.448546, 56.118844, 55.520822, 31.693752, 25.417006, 21.913251, 56.093521, 51.574358, 29.418027, 26.559331, 13.110983, 29.189976, 44.844847, 45.348469, 30.139829, 13.444924, 35.849832, 38.010998, 47.049244, 0.908892, 61.706011, 39.125158, 15.152509, 53.220455, 12.158731, 37.307119, 16.581720, 33.159723, 1.849636, 16.863361, 2.630103, 21.639140, 17.156519, 53.265375, 17.019751, 36.686576, 25.737190, 52.041153, 3.069926, 9.906565, 59.476001, 21.902456, 11.320656, 24.397814, 57.773307, 33.411508, 22.900860, 5.285949, 40.039071, 37.684601, 28.090283, 46.848186, 27.699410, 17.740758, 35.884186, 30.123421, 1.930756, 36.853689, 37.614603, 26.633125, 44.014842, 42.049829, 57.659914, 57.611987, 57.697324, 20.857482, 43.484905, 41.927780, 46.702685, 14.380282, 16.631426, 14.863691, 40.445941, 43.096092, 12.913126, 56.547698, 48.884008, 11.270544, 8.193343, 48.743319, 12.948250, 15.977381, 50.751738, 48.842139, 58.980522, 35.286922, 34.005103, 4.367443, 54.891066, 10.705366, 28.023788, 46.930170, 59.320228, 29.000221, 52.128639, 3.464996, 9.794018, 30.322184, 1.779277, 34.436670, 61.701269, 12.857869, 7.137470, 6.282169, 14.864851, 3.314361, 58.294939, 32.230116, 13.031572, 8.446327, 23.435570, 55.003166, 31.503649, 27.924433, 52.648502, 1.330544, 12.128877, 55.558976, 33.827311, 8.226199, 8.885578, 49.886749, 18.474381, 37.918723, 15.315048, 54.934564, 1.621880, 21.602938, 10.310688, 22.117892, 44.117538, 39.757762, 40.052200, 45.098723, 58.235251, 22.893885, 58.723778, 53.050922, 60.979581, 9.238552, 34.271338, 56.490600, 54.765139, 22.600973, 34.597830, 37.991743, 47.773039, 26.158762, 3.181490, 9.571571, 45.569893, 13.142289, 0.289508, 35.827180, 57.133571, 16.708934, 34.434373, 5.461506, 32.264792, 32.479184, 42.533005, 14.564972, 26.781087, 20.885015, 38.114583, 18.840409, 6.380296, 8.014238, 30.804273, 44.222246, 18.917076, 15.662650, 16.103883, 29.411306, 55.437138, 54.923490, 20.453223, 45.054393, 45.359123, 7.674536, 42.405291, 46.557097, 16.274354, 13.817372, 27.472728, 42.364067, 34.771844, 15.807818, 28.620238, 42.429334, 54.132845, 1.083473, 44.642241, 41.557836, 27.407360, 43.022644, 45.630803, 14.237543, 50.190065, 1.208106, 26.829218, 60.720590, 33.498761, 27.481631, 36.913768, 19.967775, 5.288361, 6.006031, 48.122149, 53.015358, 34.533982, 22.852404, 52.900489, 8.205593, 27.611010, 58.251586, 9.479589, 46.809781, 61.860038, 49.741664, 47.603430, 31.764300, 19.267849, 50.584245, 39.032901, 42.087479, 22.714417, 38.955651, 54.489064, 49.205595, 28.476537, 20.365515, 12.375791, 37.460263, 60.694066, 43.785026, 27.861493, 14.827587, 48.809182, 42.501128, 40.020437, 24.216135, 42.820496, 5.289740, 45.030234, 52.189552, 3.135200, 56.516504, 2.851720, 46.701655, 24.804013, 32.579388, 3.942634, 32.401366, 43.275523, 38.069395, 28.961383, 2.911476, 54.234307, 48.947156, 8.484345, 35.702882, 29.208313, 23.675987, 43.663489, 44.241220, 14.378358, 11.999271, 19.755224, 23.195867, 36.543122, 57.975454, 31.225160, 9.696873, 57.139068, 35.084299, 56.043615, 15.758508, 9.513408, 56.903014, 38.430911, 46.071453, 6.905439, 32.521960, 40.655409, 57.341548, 22.131224, 46.027218, 51.854485, 7.416427, 32.114807, 24.834228, 47.002588, 47.481706, 41.369309, 41.315571, 13.147178, 27.838607, 33.169845, 32.202417, 33.920415, 35.357345, 42.306983, 20.355095, 24.821016, 57.720327, 36.113490, 48.992098, 38.142167, 28.345252, 36.412723, 23.160256, 1.926978, 20.248958, 20.943355, 9.853462, 10.933871, 43.363477, 21.719045, 41.797415, 4.372584, 34.643256, 52.829725, 30.821393, 41.017090, 38.392369, 22.010650, 4.004174, 0.048996, 52.393775, 10.968486, 54.281244, 10.073143, 44.905809, 31.408391, 54.149383, 5.481134, 1.121732, 9.690555, 60.185472, 18.915185, 39.726486, 30.765696, 44.312640, 43.535930, 53.406814, 12.762302, 14.068908, 42.750552, 47.788847, 22.768471, 0.266539, 44.573115, 39.314977, 16.359629, 60.256357, 26.292842, 52.467279, 34.731929, 0.399658, 19.185386, 38.881680, 3.813973, 51.935439, 60.963734, 13.459597, 60.301362, 34.608242, 56.328306, 26.697924, 7.450098, 10.962003, 6.883943, 8.324210, 42.876054, 42.884336, 32.745378, 60.394626, 10.463841, 55.506075, 49.924682, 42.094661, 5.818699, 14.248400, 24.897595, 51.243903, 56.953320, 29.503397, 25.155886, 32.165526, 16.942868, 54.119398, 9.217679, 47.660146, 36.756722, 5.316079, 5.235098, 22.685578, 22.098009, 31.385472, 58.861056, 37.609957, 30.240984, 37.031930, 17.379746, 17.092970, 15.624349, 29.393976, 5.767816, 54.810008, 2.549845, 41.554991, 3.063378, 42.970011, 43.418556, 26.916415, 33.641414, 1.891468, 20.139801, 42.451352, 11.231604, 20.775792, 18.958394, 57.874210, 24.698026, 23.842446, 56.367316, 55.959838, 41.021144, 34.292601, 51.357473, 35.020960, 16.986309, 1.314588, 31.434399, 33.976744, 61.737270, 45.505226, 13.881050, 5.482564, 5.192346, 22.625238, 61.186610, 24.366848, 36.404972, 37.540893, 26.672303, 52.077408, 5.061782, 36.871089, 46.913643, 29.425160, 42.305107, 51.706409, 52.103162, 13.786979, 51.137476}, 822, output, 63);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 63; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [12, 18, 13, 18, 7, 17, 11, 6, 13, 17, 12, 12, 13, 12, 17, 11, 16, 13, 9, 5, 12, 13, 20, 7, 9, 8, 12, 13, 8, 12, 9, 10, 18, 13, 13, 18, 17, 14, 14, 13, 11, 12, 26, 16, 13, 20, 17, 15, 19, 10, 7, 14, 21, 10, 14, 13, 22, 15, 10, 4, 15, 13, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 63; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 8: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST8(void)
{
// informacje o teście
test_start(8, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {11, 9, 5, 11, 9, 5, 7, 6, 5, 6};
int output[] = {-1, 1, 0, 1, -1, -2, -2, -1, 0, -2};
printf("#####START#####");
int res = create_histogram((float[]){1.411731, 6.164065, 9.550608, 2.097330, 3.549786, 0.956541, 4.238586, 8.704422, 9.686125, 6.065459, 0.806826, 4.539103, 3.499804, 8.555641, 4.714447, 3.919298, 0.287735, 3.192498, 4.431192, 7.636086, 6.042612, 10.801061, 0.374990, 5.138826, 9.442125, 1.230041, 1.600287, 4.507115, 2.168112, 1.231663, 3.452024, 0.513705, 1.095722, 2.793962, 2.275182, 9.234740, 3.168618, 1.410920, 6.558245, 3.224430, 1.724269, 8.910182, 9.474173, 0.427321, 4.511281, 0.969919, 10.696242, 1.586473, 9.843620, 5.995901, 1.362062, 7.484962, 6.702560, 5.526020, 8.623948, 0.539967, 7.430585, 5.574125, 0.892592, 4.319218, 3.566822, 6.781997, 7.765114, 0.231397, 6.099239, 3.067890, 5.910927, 10.427178, 0.504059, 4.554958, 10.789451, 10.677566, 4.230644, 7.550792, 8.460206, 7.278405, 2.276652, 3.585147, 3.509114}, 79, output, 10);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 10; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [11, 9, 5, 11, 9, 5, 7, 6, 5, 6]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 10; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 9: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST9(void)
{
// informacje o teście
test_start(9, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0};
int output[] = {1, 1, 1, -1, -1, 1, 0, -1, 1, 2, 0};
printf("#####START#####");
int res = create_histogram((float[]){2.178237}, 1, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 10: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST10(void)
{
// informacje o teście
test_start(10, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {4};
int output[] = {-1};
printf("#####START#####");
int res = create_histogram((float[]){7.402824, 10.180452, 7.844256, 3.210592, 9.754862, 9.729049, 7.019261, 2.594121, 8.967428, 9.171932, 9.810714, 4.842452, 2.891282, 7.482043, 3.145203, 3.742174, 4.941085, 7.455413, 3.988075, 8.335422, 4.831512, 1.130901, 10.994587, 7.054107, 10.674019, 4.195143, 9.692916, 10.904550, 4.249207, 1.353987, 6.344560, 6.961610, 4.139626, 0.666705, 9.396565, 3.905291, 4.844941, 9.850950, 7.694720, 3.337505, 4.344161, 2.841703, 6.067131, 5.267122, 2.708562, 3.749673, 3.185020, 8.383703, 10.737865, 2.154967, 8.272157, 5.903535, 8.471791, 8.819737, 5.861971, 6.679765, 10.971073, 2.379158, 0.322953, 10.573521, 8.902322, 0.442521, 0.352173, 6.693311, 6.523021, 1.613806, 1.689041, 9.323567, 10.760533, 9.976505, 3.444923, 2.327158, 9.803090, 5.179249, 5.234755, 7.647720, 6.072069, 10.114530}, 78, output, 1);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 1; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [4]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 1; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 11: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST11(void)
{
// informacje o teście
test_start(11, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
printf("#####START#####");
int res = create_histogram((float[]){8.382878, 1.724498, 6.022452, 1.590785, 8.332282, 9.666826, 6.917846, 9.908814, 9.739670}, 14, NULL, 19);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 12: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST12(void)
{
// informacje o teście
test_start(12, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {-1, -1, -1, 1, -2, -2, 1, 0, -1, -2, -2};
printf("#####START#####");
int res = create_histogram(NULL, 14, output, 17);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 13: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST13(void)
{
// informacje o teście
test_start(13, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {-1, -1, -1, 1, -2, -2, 1, 0, -1, -2, -2};
printf("#####START#####");
int res = create_histogram((float[]){8.382878, 1.724498, 6.022452, 1.590785, 8.332282, 9.666826, 6.917846, 9.908814, 9.739670}, 0, output, 13);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 14: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST14(void)
{
// informacje o teście
test_start(14, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {-1, -1, -1, 1, -2, -2, 1, 0, -1, -2, -2};
printf("#####START#####");
int res = create_histogram((float[]){8.382878, 1.724498, 6.022452, 1.590785, 8.332282, 9.666826, 6.917846, 9.908814, 9.739670}, 14, output, 0);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 15: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST15(void)
{
// informacje o teście
test_start(15, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {-1, -1, -1, 1, -2, -2, 1, 0, -1, -2, -2};
printf("#####START#####");
int res = create_histogram((float[]){8.382878, 1.724498, 6.022452, 1.590785, 8.332282, 9.666826, 6.917846, 9.908814, 9.739670}, -12, output, 15);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 16: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST16(void)
{
// informacje o teście
test_start(16, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {-1, -1, -1, 1, -2, -2, 1, 0, -1, -2, -2};
printf("#####START#####");
int res = create_histogram((float[]){8.382878, 1.724498, 6.022452, 1.590785, 8.332282, 9.666826, 6.917846, 9.908814, 9.739670}, 18, output, -20);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 17: Sprawdzanie poprawności działania funkcji display
//
void UTEST17(void)
{
// informacje o teście
test_start(17, "Sprawdzanie poprawności działania funkcji display", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int tab[] = {0, -4, 6, 5, 3, 1, 4, -6};
//-------------1-----------------------
printf("\n***TEST 1***\n\n");
printf("***START***\n");
display_vector(tab, 0);
printf("***END***\n");
//-------------2-----------------------
printf("\n***TEST 2***\n\n");
printf("***START***\n");
display_vector(tab, -8);
printf("***END***\n");
//-------------3-----------------------
printf("\n***TEST 3***\n\n");
printf("***START***\n");
display_vector(tab, 8);
printf("***END***\n");
//-------------4-----------------------
printf("\n***TEST 4***\n\n");
printf("***START***\n");
display_vector(tab, 8 - 1);
printf("***END***\n");
onerror_terminate(); // przerwanie wszystkich testów jednostkowych (np. coś jest mocno nie tak z kodem)
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 18: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST18(void)
{
// informacje o teście
test_start(18, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 8;
const float expected_array[] = {7.000000, 1.000000, 3.000000, -2.000000, -8.000000, 4.000000, 1.000000, 10.000000, 0.000000};
float dest[9];
int result = read_vector_float(dest, 9, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [7.000000, 1.000000, 3.000000, -2.000000, -8.000000, 4.000000, 1.000000, 10.000000, 0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 19: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST19(void)
{
// informacje o teście
test_start(19, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 11;
const float expected_array[] = {-7.000000, 8.000000, -9.000000, 0.000000, 10.000000, -3.000000, -2.000000, 1.000000, 10.000000, -10.000000, -7.000000, -4.000000};
float dest[12];
int result = read_vector_float(dest, 12, -4);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-7.000000, 8.000000, -9.000000, 0.000000, 10.000000, -3.000000, -2.000000, 1.000000, 10.000000, -10.000000, -7.000000, -4.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 20: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST20(void)
{
// informacje o teście
test_start(20, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 0;
const float expected_array[] = {0.000000};
float dest[5];
int result = read_vector_float(dest, 5, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 21: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST21(void)
{
// informacje o teście
test_start(21, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 10;
const float expected_array[] = {-2.000000, 0.000000, -2.000000, 5.000000, -4.000000, 0.000000, -4.000000, 3.000000, -9.000000, -8.000000};
float dest[10];
int result = read_vector_float(dest, 10, -10);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-2.000000, 0.000000, -2.000000, 5.000000, -4.000000, 0.000000, -4.000000, 3.000000, -9.000000, -8.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 22: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST22(void)
{
// informacje o teście
test_start(22, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[10];
printf("#####START#####");
int result = read_vector_float(dest, 0, -9);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 23: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST23(void)
{
// informacje o teście
test_start(23, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[6];
printf("#####START#####");
int result = read_vector_float(dest, -7, 8);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 24: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST24(void)
{
// informacje o teście
test_start(24, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
printf("#####START#####");
int result = read_vector_float(NULL, -7, -10);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
enum run_mode_t { rm_normal_with_rld = 0, rm_unit_test = 1, rm_main_test = 2 };
int __wrap_main(volatile int _argc, char** _argv, char** _envp)
{
int volatile vargc = _argc;
char ** volatile vargv = _argv, ** volatile venvp = _envp;
volatile enum run_mode_t run_mode = rm_unit_test; // -1
volatile int selected_test = -1;
if (vargc > 1)
{
char* smode = strtok(vargv[1], ",");
char* stest = strtok(NULL, "");
char *errptr = NULL;
run_mode = (enum run_mode_t)strtol(smode, &errptr, 10);
if (*errptr == '\x0')
{
memmove(vargv + 1, vargv + 2, sizeof(char*) * (vargc - 1));
vargc--;
if (stest != NULL)
{
int val = (int)strtol(stest, &errptr, 10);
if (*errptr == '\x0')
selected_test = val;
}
}
}
// printf("runmode=%d; selected_test=%d\n", run_mode, selected_test);
// inicjuj testy jednostkowe
unit_test_init(run_mode, "unit_test_v2.c");
test_limit_init();
rldebug_set_reported_severity_level(MSL_FAILURE);
if (run_mode == rm_normal_with_rld)
{
// konfiguracja ograniczników
rldebug_reset_limits();
// uruchom funkcję main Studenta a potem wyświetl podsumowanie sterty i zasobów
volatile int ret_code = rdebug_call_main(tested_main, vargc, vargv, venvp);
rldebug_reset_limits();
int leaks_detected = rldebug_show_leaked_resources(0);
if (leaks_detected)
raise(SIGHEAP);
return ret_code;
}
if (run_mode == rm_unit_test)
{
test_title("Testy jednostkowe");
void (*pfcn[])(void) =
{
UTEST1, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST2, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST3, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST4, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST5, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST6, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST7, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST8, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST9, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST10, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST11, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST12, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST13, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST14, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST15, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST16, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST17, // Sprawdzanie poprawności działania funkcji display
UTEST18, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST19, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST20, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST21, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST22, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST23, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST24, // Sprawdzanie poprawności działania funkcji read_vector_float
NULL
};
for (int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx]();
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(24); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
if (run_mode == rm_main_test)
{
test_title("Testy funkcji main()");
void (*pfcn[])(int, char**, char**) =
{
NULL
};
for (volatile int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx](vargc, vargv, venvp);
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(0); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
printf("*** Nieznana wartość RunMode: %d", (int)run_mode);
abort();
}